﻿// Decompiled with JetBrains decompiler
// Type: cXMLWizard.CUiParameterContextMenu
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.OLPEditor.cXMLWizard.Resources;
using LayersParser.Objects;
using LayersParser.User_Controls;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace cXMLWizard;

public class CUiParameterContextMenu : TxForm
{
  private object parent;
  private Size dialogSize;
  private IContainer components;
  private ParamConfigurator paramConfigurator1;
  private Button OKBtn;
  private Button closeBtn;
  private Button applyBtn;

  public CUiParameterContextMenu()
  {
    this.InitializeComponent();
    this.dialogSize = ((Form) this).Size;
    ((System.Windows.Forms.Control) this).SizeChanged += new EventHandler(this.SizedChanged);
    if (this.paramConfigurator1.TextBox.Text == "" || !this.paramConfigurator1.HasValues)
    {
      this.OKBtn.Enabled = false;
      this.applyBtn.Enabled = false;
    }
    this.paramConfigurator1.TextBox.TextChanged += new EventHandler(this.TextBox_TextChanged);
    this.paramConfigurator1.ValuesChanged += new ParamConfigurator.ValuesChangedEventHandler(this.ParamConfigurator1_ValuesChanged);
  }

  private void ParamConfigurator1_ValuesChanged()
  {
    if (this.paramConfigurator1.TextBox.Text == "" || !this.paramConfigurator1.HasValues)
    {
      this.OKBtn.Enabled = false;
      this.applyBtn.Enabled = false;
    }
    else
    {
      this.OKBtn.Enabled = true;
      this.applyBtn.Enabled = true;
    }
  }

  public object Control
  {
    get => this.parent;
    set => this.parent = value;
  }

  public ParamConfigurator ParamConfigurator
  {
    get => this.paramConfigurator1;
    set => this.paramConfigurator1 = value;
  }

  public string CommandText { get; internal set; }

  private void Close(object sender, EventArgs e)
  {
    this.UnregisterEvents();
    ((Form) this).Close();
  }

  private void Apply(object sender, EventArgs e)
  {
    if (this.paramConfigurator1.Param.Name != null && this.paramConfigurator1.Param.Name != "")
    {
      if (this.CommandText.ToLower().Contains(this.paramConfigurator1.Param.Name.ToLower()))
      {
        int num1 = (int) TxMessageBox.Show(cXMLWizardStringTable.PARAMETER_EXISTS_MESSAGE, cXMLWizardStringTable.NAME, MessageBoxButtons.OK, MessageBoxIcon.Hand);
      }
      else
        ((CUiMainwindow) this.parent).Parameter = this.paramConfigurator1.Param;
    }
    else
    {
      int num2 = (int) TxMessageBox.Show(cXMLWizardStringTable.GIVE_PARAMETER_NAME, cXMLWizardStringTable.NAME, MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
  }

  private void OKpushed(object sender, EventArgs e)
  {
    if (this.paramConfigurator1.Param.Name != null && this.paramConfigurator1.Param.Name != "")
    {
      if (this.CommandText.ToLower().Contains(this.paramConfigurator1.Param.Name.ToLower()))
      {
        int num1 = (int) TxMessageBox.Show(cXMLWizardStringTable.PARAMETER_EXISTS_MESSAGE, cXMLWizardStringTable.NAME, MessageBoxButtons.OK, MessageBoxIcon.Hand);
      }
      else
      {
        ((CUiMainwindow) this.parent).Parameter = this.paramConfigurator1.Param;
        this.UnregisterEvents();
        ((Form) this).Close();
      }
    }
    else
    {
      int num2 = (int) TxMessageBox.Show(cXMLWizardStringTable.GIVE_PARAMETER_NAME, cXMLWizardStringTable.NAME, MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
  }

  private void UnregisterEvents()
  {
    this.paramConfigurator1.TextBox.TextChanged -= new EventHandler(this.TextBox_TextChanged);
    this.paramConfigurator1.ValuesChanged -= new ParamConfigurator.ValuesChangedEventHandler(this.ParamConfigurator1_ValuesChanged);
  }

  private void SizedChanged(object sender, EventArgs e) => ((Form) this).Size = this.dialogSize;

  private void TextBox_TextChanged(object sender, EventArgs e)
  {
    if (this.paramConfigurator1.TextBox.Text == "" || !this.paramConfigurator1.HasValues)
    {
      this.OKBtn.Enabled = false;
      this.applyBtn.Enabled = false;
    }
    else
    {
      this.OKBtn.Enabled = true;
      this.applyBtn.Enabled = true;
    }
  }

  public void DisableOKButton()
  {
    this.OKBtn.Enabled = false;
    this.applyBtn.Enabled = false;
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    Param obj = new Param();
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiMainwindow));
    this.paramConfigurator1 = new ParamConfigurator();
    this.OKBtn = new Button();
    this.closeBtn = new Button();
    this.applyBtn = new Button();
    ((System.Windows.Forms.Control) this).SuspendLayout();
    this.paramConfigurator1.Control = (object) null;
    this.paramConfigurator1.Location = new Point(12, 7);
    this.paramConfigurator1.Name = "paramConfigurator1";
    this.paramConfigurator1.Param = obj;
    this.paramConfigurator1.Size = new Size(576, 159);
    this.paramConfigurator1.TabIndex = 0;
    this.OKBtn.Location = new Point(40, 230);
    this.OKBtn.Name = "buttonOK";
    this.OKBtn.Size = new Size(97, 23);
    this.OKBtn.TabIndex = 1;
    this.OKBtn.Text = "OK";
    this.OKBtn.UseVisualStyleBackColor = true;
    this.OKBtn.Click += new EventHandler(this.OKpushed);
    this.closeBtn.Location = new Point(246, 230);
    this.closeBtn.Name = "closeBtn";
    this.closeBtn.Size = new Size(97, 23);
    this.closeBtn.TabIndex = 2;
    this.closeBtn.Text = cXMLWizardStringTable.CLOSE_LABEL;
    this.closeBtn.UseVisualStyleBackColor = true;
    this.closeBtn.Click += new EventHandler(this.Close);
    this.applyBtn.Location = new Point(143, 230);
    this.applyBtn.Name = "buttonApply";
    this.applyBtn.Size = new Size(97, 23);
    this.applyBtn.TabIndex = 3;
    this.applyBtn.Text = cXMLWizardStringTable.APPLY_LABEL;
    this.applyBtn.UseVisualStyleBackColor = true;
    this.applyBtn.Click += new EventHandler(this.Apply);
    this.applyBtn.Enabled = false;
    ((ContainerControl) this).AutoScaleDimensions = new SizeF(6f, 13f);
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Form) this).ClientSize = new Size(600, 200);
    ((System.Windows.Forms.Control) this).Controls.Add((System.Windows.Forms.Control) this.applyBtn);
    ((System.Windows.Forms.Control) this).Controls.Add((System.Windows.Forms.Control) this.closeBtn);
    ((System.Windows.Forms.Control) this).Controls.Add((System.Windows.Forms.Control) this.OKBtn);
    ((System.Windows.Forms.Control) this).Controls.Add((System.Windows.Forms.Control) this.paramConfigurator1);
    ((Form) this).MaximizeBox = false;
    ((System.Windows.Forms.Control) this).MaximumSize = new Size(800, 400);
    ((Form) this).MinimizeBox = false;
    ((System.Windows.Forms.Control) this).MinimumSize = new Size(400, 200);
    ((Form) this).Size = new Size(400, 300);
    ((System.Windows.Forms.Control) this).Name = "ParameterContextMenu";
    ((Form) this).SizeGripStyle = SizeGripStyle.Hide;
    ((System.Windows.Forms.Control) this).Text = cXMLWizardStringTable.EDIT_NEW_PARAMETER_NAME;
    ((System.Windows.Forms.Control) this).ResumeLayout(false);
  }
}
